package com.cssw.fyzb.busi.api.live;

import com.cssw.fyzb.core.exception.BizException;
import com.cssw.fyzb.core.model.vo.live.SaveAnchorVo;
import com.cssw.fyzb.busi.service.live.AnchorService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 开通直播
 *
 * @description:
 * @author: zzf
 * @time: 2020/12/25 15:01
 */
@Function(description = "开通直播", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户ID", required = true)
})
@Component
public class SaveAnchor implements Action {
    private final static Logger logger = LoggerFactory.getLogger(SaveAnchor.class);

    @Autowired
    AnchorService anchorService;

    @Override
    public Response execute(Request request) {
        Long userId = request.getLong("userId");
        try {
            Long anchorId = anchorService.saveAnchor(userId);
            return Response.success().put("data",new SaveAnchorVo(anchorId));
        } catch (BizException e) {
            return Response.fail(e.getErrMsg(), e.getErrCode());
        } catch (Exception e) {
            logger.debug("", e);
            return Response.fail("开播失败");
        }
    }
}
